function del_child_node()
{
    var elem = document.getElementById("show");
	var elemm = document.getElementById("search");  
    while(elem.hasChildNodes()) //当elem下还存在子节点时 循环继续  
    {  
        elem.removeChild(elem.firstChild);  
    } 
	while(elemm.hasChildNodes())
	{
		elemm.removeChild(elemm.firstChild);
	}
}

function edit_student_backpage()
{
	var class_sl = document.getElementById("sl_id");
	var sl_index = class_sl.selectedIndex;
	document.getElementById("st_tb").innerHTML = "";
	document.getElementById("page_value").value = (Number(document.getElementById("page_value").value)-1);
	if(document.getElementById("page_value").value < 1)
	{
		document.getElementById("page_value").value = 1;
	}
	document.getElementById('myiframe').src = 'displaystudent.php?page_input='+document.getElementById("page_value").value+"&class="+class_sl.options[sl_index].text;
}

function edit_student_nextpage()
{
	var class_sl = document.getElementById("sl_id");
	var sl_index = class_sl.selectedIndex;
	document.getElementById("st_tb").innerHTML = "";
	document.getElementById("page_value").value = (Number(document.getElementById("page_value").value)+1);
	if(Number(document.getElementById("page_value").value) > Number(document.getElementById("page_nums").value))
	{
		document.getElementById("page_value").value = document.getElementById("page_nums").value;
	}
	document.getElementById('myiframe').src = 'displaystudent.php?page_input='+document.getElementById("page_value").value+"&class="+class_sl.options[sl_index].text;
}

function edit_student_pagego()
{
	var class_sl = document.getElementById("sl_id");
	var sl_index = class_sl.selectedIndex;
	document.getElementById("st_tb").innerHTML = "";
	document.getElementById('myiframe').src = 'displaystudent.php?page_input='+document.getElementById("page_value").value+"&class="+class_sl.options[sl_index].text;
}

function student_select_class()
{
	var class_sl = document.getElementById("sl_id");
	var sl_index = class_sl.selectedIndex;
	document.getElementById("page_value").value = 1;
	document.getElementById('myiframe').src = 'displaystudent.php?page_input=1'+"&class="+class_sl.options[sl_index].text;
}

function search_stu()
{
	var search_value = document.getElementById("id_search_input").value;
	document.getElementById('myiframe').src = 'display_search.php?search_input='+search_value;
}
function del_stu()
{
	var isrealy = window.confirm("数据删除后不能撤销，确认要删除吗？");
	if(isrealy)
	{
		var search_value = document.getElementById("id_search_input").value;
		document.getElementById('myiframe').src = 'del_student.php?search_input='+search_value;
	}
}
function edit_student()
{
	del_child_node();

	//选择班级及学生列表
	var select_cl = document.createElement("select");
	select_cl.id = "sl_id";
	select_cl.onchange = student_select_class;
	var table_st = document.createElement("table");
	table_st.id = "st_tb";
	table_st.border = "1";
	var element = document.getElementById("show");
	element.appendChild(select_cl);
	element.appendChild(table_st);
	var iframe_st = document.createElement("iframe");
	iframe_st.id = "myiframe";
	iframe_st.border = 0;
	iframe_st.width = 0;
	iframe_st.height = 0;
	iframe_st.style.display = "none";
	
	//换页部分
	var div_changepage = document.createElement("form");
	var button_back = document.createElement("button");
	var button_next = document.createElement("button");
	var button_pagego = document.createElement("button");
	var input_page = document.createElement("input");
	var class_index = document.createElement("input");
	var page_nums = document.createElement("input");

	div_changepage.appendChild(button_back);
	div_changepage.appendChild(button_next);
	div_changepage.appendChild(input_page);
	div_changepage.appendChild(page_nums);
	div_changepage.appendChild(class_index);
	div_changepage.appendChild(button_pagego);
	page_nums.style.display = "none";
	class_index.style.display = "none";
	page_nums.id = "page_nums";
	class_index.id = "class_indexid";
	input_page.type = "input";
	input_page.value = "1";
	class_index.value = 0;
	input_page.id = "page_value";
	input_page.name = "page_input";
	input_page.size = "10";
	button_back.innerText = "上一页";
	button_next.innerText = "下一页";
	button_pagego.innerText = "确定";
	button_next.type="button";
	button_back.type="button";
	button_pagego.type = "button";
	button_pagego.onclick = edit_student_pagego;
	button_next.onclick = edit_student_nextpage;
	button_back.onclick = edit_student_backpage;
	div_changepage.method = "post";

	//搜索部分
	var div_search = document.createElement("div");
	var input_search = document.createElement("input");
	var button_search = document.createElement("button");
	var button_del = document.createElement("button");

	button_search.innerText = "搜索";
	button_search.type = "button";
	button_search.onclick = search_stu;
	button_del.innerText = "删除";
	button_del.type = "button";
	button_del.onclick = del_stu;
	button_del.style.visibility = "hidden";
	button_del.id = "button_del";

	input_search.id = "id_search_input";
	input_search.size = "10";
	var table_search = document.createElement("table");
	table_search.id = "search_tb";
	table_search.border = "1";

	div_search.appendChild(input_search);
	div_search.appendChild(button_search);
	div_search.appendChild(table_search);
	div_search.appendChild(button_del);

	var element_search = document.getElementById("search");
	element.appendChild(div_changepage);
	element.appendChild(iframe_st);
	element_search.appendChild(div_search);
	//table_st.innerHTML = "<tr><td>姓名</td><td>科目</td><td>成绩</td>";
	//var table_st = document.getElementById("st_tb");
	//table_st.border="1";
	//table_st.innerHTML = "<tr><td>姓名</td><td>科目</td><td>成绩</td>";
	document.getElementById('myiframe').src = 'displaystudent.php?page_input='+input_page.value;
	
}
function add_student()
{
	del_child_node();
	var para = document.createElement("form");
	para.innerHTML = "<h2>手动添加</h2>";
	var name_node = document.createTextNode("姓名: ");
	var class_node = document.createTextNode("班级: ");
	var id_node = document.createTextNode("学号: ");
	
	var element = document.getElementById("show");
	para.action = "add_student.php";
	para.method = "post";
	para.id = "form_id";
	para.border = "1";
	element.appendChild(para);

	var name_input = document.createElement("input");
	var class_input = document.createElement("input");
	var id_input = document.createElement("input");
	var c_submit= document.createElement("input");
	name_input.id = "form_id";
	name_input.type = "text";
	name_input.name= "name";
	name_input.size = "10";
	class_input.id = "form_id";
	class_input.type = "text";
	class_input.name= "class";
	class_input.size = "10";
	id_input.id = "form_id";
	id_input.type = "text";
	id_input.name= "id";
	id_input.size = "10";
	c_submit.id = "submit_id"
	c_submit.type = "submit";
	c_submit.value = "添加";
	c_submit.setAttribute("style", "margin-left:5px");
	para.appendChild(name_node);
	para.appendChild(name_input);
	para.appendChild(class_node);
	para.appendChild(class_input);
	para.appendChild(id_node);
	para.appendChild(id_input);
	para.appendChild(c_submit);

	var uf_form = document.createElement("form");
	uf_form.innerHTML = "<h2>从文件添加</h2>";
	uf_form.action = "add_student_fromfile.php";
	uf_form.method = "post";
	uf_form.id = "uf_form";
	uf_form.border = "1";
	uf_form.enctype = "multipart/form-data";
	element.appendChild(uf_form);
	var file_input = document.createElement("input");
	file_input.id = "file";
	file_input.type = "file";
	file_input.name = "file";
	var file_submit= document.createElement("input");
	file_submit.id = "filesub_id";
	file_submit.type = "submit";
	file_submit.value = "从文件导入";
	uf_form.appendChild(file_input);
	uf_form.appendChild(file_submit);

}
function add_test()
{
	// var para = document.createElement("p");
	// var node = document.createTextNode("这是一个新段落。");
	// para.appendChild(node);
	// var element = document.getElementById("show");
	// element.appendChild(para);
	del_child_node();
	var para = document.createElement("form");
	var node = document.createTextNode("考试科目: ");
	para.appendChild(node);
	var element = document.getElementById("show");
	para.action = "add_score.php";
	para.method = "post";
	para.id = "form_id";
	element.appendChild(para);

	var c_input = document.createElement("input");
	var c_submit= document.createElement("input");
	var p_form = document.getElementById("form_id");
	c_input.id = "form_id";
	c_input.type = "text";
	c_input.name= "score";
	c_submit.id = "submit_id"
	c_submit.type = "submit";
	c_submit.value = "添加";
	c_submit.setAttribute("style", "margin-left:5px");
	p_form.appendChild(c_input);
	p_form.appendChild(c_submit);
}

function change_password()
{
	del_child_node();
	var para = document.createElement("form");
	var id_node = document.createTextNode("ID: ");
	var pw_node = document.createTextNode(" new password: ");
	para.appendChild(id_node);
	var element = document.getElementById("show");
	para.action = "change_password.php";
	para.method = "post";
	para.id = "form_id";
	element.appendChild(para);

	var id_input = document.createElement("input");
	var pw_input = document.createElement("input");
	var c_submit= document.createElement("input");
	var p_form = document.getElementById("form_id");

	id_input.id = "form_id";
	id_input.type = "text";
	id_input.name= "id_input";

	pw_input.id = "form_id";
	pw_input.type = "text";
	pw_input.name= "pw";

	c_submit.id = "submit_id"
	c_submit.type = "submit";
	c_submit.value = "修改";
	c_submit.setAttribute("style", "margin-left:5px");

	p_form.appendChild(id_input);
	para.appendChild(pw_node);
	p_form.appendChild(pw_input);
	p_form.appendChild(c_submit);
}

function del_score()
{
	del_child_node();
	var para = document.createElement("form");
	var name_node = document.createTextNode("姓名: ");
	var subject_node = document.createTextNode(" 科目: ");
	var element = document.getElementById("show");
	para.action = "del_score.php";
	para.method = "post";
	para.id = "form_id";
	element.appendChild(para);

	var name_input = document.createElement("input");
	var subject_input = document.createElement("input");
	var c_submit= document.createElement("input");
	var p_form = document.getElementById("form_id");

	name_input.id = "name_id";
	name_input.type = "text";
	name_input.name= "name";

	subject_input.id = "subject_id";
	subject_input.type = "text";
	subject_input.name= "subject";

	c_submit.id = "submit_id"
	c_submit.type = "submit";
	c_submit.value = "删除";
	c_submit.setAttribute("style", "margin-left:5px");

	para.appendChild(name_node);
	p_form.appendChild(name_input);
	para.appendChild(subject_node);
	p_form.appendChild(subject_input);
	p_form.appendChild(c_submit);
}

function change_score()
{
	del_child_node();
	var para = document.createElement("form");
	var name_node = document.createTextNode("姓名: ");
	var subject_node = document.createTextNode(" 科目: ");
	var score_node = document.createTextNode(" 新成绩: ");
	var element = document.getElementById("show");
	para.action = "change_score.php";
	para.method = "post";
	para.id = "form_id";
	element.appendChild(para);

	var name_input = document.createElement("input");
	var subject_input = document.createElement("input");
	var score_input = document.createElement("input");
	var c_submit= document.createElement("input");
	var p_form = document.getElementById("form_id");

	name_input.id = "name_id";
	name_input.type = "text";
	name_input.name= "name";

	subject_input.id = "subject_id";
	subject_input.type = "text";
	subject_input.name= "subject";

	score_input.id = "score_id";
	score_input.type = "text";
	score_input.name= "score";

	c_submit.id = "submit_id"
	c_submit.type = "submit";
	c_submit.value = "修改";
	c_submit.setAttribute("style", "margin-left:5px");

	para.appendChild(name_node);
	p_form.appendChild(name_input);
	para.appendChild(subject_node);
	p_form.appendChild(subject_input);
	para.appendChild(score_node);
	p_form.appendChild(score_input);
	p_form.appendChild(c_submit);
}